package com.huifaapp.mall.adapter;

import android.content.Context;
import android.graphics.Paint;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.huifaapp.mall.R;
import com.huifaapp.mall.activity.DetailsofPaymentActivity;
import com.huifaapp.mall.afinal.Constants;
import com.huifaapp.mall.bean.DetailsPayShoppingCart;
import com.huifaapp.mall.bean.GoodsListBean;
import com.huifaapp.mall.bean.PayDetails;
import com.huifaapp.mall.uitils.UtilsImage;
import com.tencent.mm.sdk.openapi.IWXAPI;
import com.tencent.mm.sdk.openapi.WXAPIFactory;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;


/**
 * 
* @ClassName: IntroductionPageAdapter 
* @Description: TODO(引导页) 
* @author lijs
* @date 2016年5月11日 下午1:34:37 
*
 */
public class DetailsofPaymentListviewAdapter extends BaseAdapter {
	private Context context;
	private LayoutInflater inflater;
	private List<GoodsListBean>  list;
	private IWXAPI api;
	private static final int SHARET_WXHY = 519;
	public DetailsofPaymentListviewAdapter(Context context, ArrayList<GoodsListBean> list) {
		this.context = context;
		this.inflater = LayoutInflater.from(context);
		this.list=list;
		// 通过WXAPIFactory工厂，获取IWXAPI的实例
		api = WXAPIFactory.createWXAPI(context, Constants.WX_APPID);
		api.registerApp(Constants.WX_APPID);
	}

    @Override
	public int getCount() {
		return list == null ? 0 : list.size();
	//Integer.MAX_VALUE;
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}


	public List<GoodsListBean> getList() {
		return list;
	}

	public DetailsofPaymentListviewAdapter setList(List<GoodsListBean> list) {
		this.list = list;
		return this;
	}

	int ds=0;
	@Override
	public  View getView(final int position, View convertView, ViewGroup parent) {
//		final ViewHolder holder;
//		if (null == convertView) {
//			convertView = inflater.inflate(R.layout.detailsofpay_listview, null);
//			holder = new ViewHolder();
//
//			convertView.setTag(holder);
//		} else {
//			holder = (ViewHolder) convertView.getTag();
//		}
//		final GoodsListBean bean=list.get(position);
//		UtilsImage.uploadimageview(holder.iv_goodsImage_lv,bean.getGoodsImg(),null,context);
//		holder.tv_PayDetails_goodsName_lv.setText(bean.getGoodsName());
//		if (bean.getParam() == ""||bean.getParam() == "null"||bean.getParam() == null) {
//			holder.tv_PayDetails_ColorSize_lv.setText("");
//		}else {
//			try {
//				JSONObject object = new JSONObject(bean.getParam());
//				if(object.getString("color").equals("")){
//					holder.tv_PayDetails_ColorSize_lv.setText("尺寸: " + object.getString("size"));
//				}else if(object.getString("size").equals("")){
//					holder.tv_PayDetails_ColorSize_lv.setText("颜色分类: " + object.getString("color"));
//				}else {
//					holder.tv_PayDetails_ColorSize_lv.setText("颜色分类: " + object.getString("color") + "; 尺寸: " + object.getString("size"));
//				}
//			} catch (JSONException e) {
//				e.printStackTrace();
//			}
//		}
//		holder.tv_PayDetails_price_lv.setText("¥"+bean.getPrice());
//		holder.tv_PayDetails_pricebefore_lv.setText("¥"+bean.getOrginPrice());
//		holder.tv_PayDetails_pricebefore_lv .getPaint().setFlags(Paint. STRIKE_THRU_TEXT_FLAG );
//		holder.tv_PayDetails_count_lv.setText("x "+bean.getCount());
		return convertView;
	}




	public static class ViewHolder {
		ImageView iv_goodsImage_lv;
		TextView tv_PayDetails_goodsName_lv;
		TextView tv_PayDetails_ColorSize_lv;
		TextView tv_PayDetails_price_lv;
		TextView tv_PayDetails_pricebefore_lv;
		TextView tv_PayDetails_count_lv;
		public ViewHolder(View convertView) {

			iv_goodsImage_lv= (ImageView) convertView.findViewById(R.id.iv_goodsImage_lv);
			tv_PayDetails_goodsName_lv= (TextView) convertView.findViewById(R.id.tv_PayDetails_goodsName_lv);
			tv_PayDetails_ColorSize_lv= (TextView) convertView.findViewById(R.id.tv_PayDetails_ColorSize_lv);
			tv_PayDetails_price_lv= (TextView) convertView.findViewById(R.id.tv_PayDetails_price_lv);
			tv_PayDetails_pricebefore_lv= (TextView) convertView.findViewById(R.id.tv_PayDetails_pricebefore_lv);
			tv_PayDetails_count_lv= (TextView) convertView.findViewById(R.id.tv_PayDetails_count_lv);
		}
		public void setdate(Context context, GoodsListBean bean){

			UtilsImage.uploadimageview(iv_goodsImage_lv,bean.getGoodsImg(),null,context);
			tv_PayDetails_goodsName_lv.setText(bean.getGoodsName());

			if (bean.getParam() == ""||bean.getParam() == "null"||bean.getParam() == null) {
				tv_PayDetails_ColorSize_lv.setText("");
			}else {
				String parem=bean.getParam().substring(1,bean.getParam().length()).
						substring(0,bean.getParam().length()-2);
					tv_PayDetails_ColorSize_lv.setText(parem);

			}
			if (bean.getIsRevice().equals("0")){
				tv_PayDetails_pricebefore_lv.setVisibility(View.GONE);
				tv_PayDetails_price_lv.setText("¥"+bean.getOrginPrice());
			}else {
				tv_PayDetails_price_lv.setText("¥" + bean.getPrice());
				tv_PayDetails_pricebefore_lv.setText("¥" + bean.getOrginPrice());
				tv_PayDetails_pricebefore_lv.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
				tv_PayDetails_count_lv.setText("x " + bean.getCount());
			}
		}

	}
}